package by.kniazhych.core.view.game {
	
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	
		import by.kniazhych.core.constants.UserColor;
		import flash.display.DisplayObject;
		import flash.display.Sprite;
		import flash.events.Event;
	

	
	public class GameContainer extends Sprite{
		static private const CELL_SIDE_SIZE:Number = 50;
		static private const LEFT_OFFSET:Number = 60;
		static private const TOP_OFFSET:Number = 60;
		private var _color:uint = UserColor.WHITE;
		
		public function GameContainer() {
			super();
			super.addEventListener(Event.ADDED, _onChildAdded);
		}
		
		//--------------------------------------------------------------------------
		//
		//  PRIVATE METHODS
		//
		//--------------------------------------------------------------------------
		
		private function _renderChild(child:DisplayObject):void {
			child.scaleX = child.scaleY = (_color == UserColor.WHITE ? 1 : -1);
		}
		
		private function _renderBoard():void {
			_renderChild(this);
			this.x = (_color == UserColor.WHITE ? 0 : 570);
			this.y = (_color == UserColor.WHITE ? 0 : 570);
		}
		//--------------------------------------------------------------------------
		//
		//  EVENT HANDLERS
		//
		//--------------------------------------------------------------------------
		
		private function _onChildAdded(e:Event):void {
			if (DisplayObject(e.target).parent == this) {
				_renderChild(e.target as DisplayObject);
			}
			_renderBoard();
		}
		
		//--------------------------------------------------------------------------
		//
		//  DATA ACSESSORS
		//
		//--------------------------------------------------------------------------
		
		public function get color():uint { return _color; }
		
		public function set color(value:uint):void {
			if (_color == value) return;
			_color = value;
			for (var i:int = 0; i < super.numChildren; i++) {
				_renderChild(super.getChildAt(i));
			}
			_renderBoard();
		}
		
		
		
	}

}